package com.gangan.controller.web;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gangan.controller.common.BaseController;
import com.gangan.model.CmsContent;
import com.gangan.model.Customer;
import com.gangan.service.ICmsContentService;
import com.gangan.service.ICustomerService;
import com.gangan.tools.MessageBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@Api(description = "*候诊人模块控制层")
@RestController
@RequestMapping("/customer")
public class CustomerController extends BaseController {

    @Autowired
    ICustomerService customerService;

    @RequestMapping(value = "/list",method = RequestMethod.GET)
    @ApiOperation(value="内容数据列表", notes="根据相关条件查询列表数据")
    public MessageBean list(Page page){
        return resultSuccess(customerService.page(page, Wrappers.<Customer>query().lambda().orderByDesc(Customer::getUpdateTime)));
    }

    @RequestMapping(value = "/del",method = RequestMethod.POST)
    @ApiOperation(value="移除内容数据", notes="根据自增主键移除数据")
    public MessageBean del(Integer id){
        return resultSuccess(customerService.removeById(id));
    }

    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @ApiOperation(value="新增内容数据", notes="将提交的数据保存到数据库")
    public MessageBean add(Customer add){
        return resultSuccess(customerService.save(add));
    }

    @RequestMapping(value = "/edit",method = RequestMethod.POST)
    @ApiOperation(value="编辑内容数据", notes="根据主键修改数据")
    public MessageBean edit(Customer edit){
        return resultSuccess(customerService.updateById(edit));
    }
}
